package main

import (
	"encoding/json"
	"fmt"
)

type Movie struct {
	Title  string   `json:title`
	Year   int      `json:year`
	Price  int      `json:rmb`
	Actors []string `json:actors`
}

func main() {
	movie := Movie{"喜剧之王", 2000, 10, []string{"xingye"}}

	jsonStr, err := json.Marshal(movie)
	if err != nil {
		fmt.Println("json error")
		return
	}
	fmt.Printf("json=%s\n", jsonStr)

	//解码json
	myMovie := Movie{}
	err = json.Unmarshal(jsonStr, &myMovie)
	if err != nil {
		fmt.Println("json error")
		return
	}
	fmt.Printf("%v\n", myMovie)
}
